home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / ADA / GNAT / !gcc / adainc / 2 / adb / a-wtmoio < prev    next >
Text File  |  1996-02-12  |  6KB  |  151 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --   A D A . T E X T _ I O . W I D E _ T E X T _ I O . M O D U L A R _ I O  --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.3 $                              --
  10. --                                                                          --
  11. --     Copyright (C) 1992,1993,1994,1995 Free Software Foundation, Inc.     --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
  22. -- MA 02111-1307, USA.                                                      --
  23. --                                                                          --
  24. -- As a special exception,  if other files  instantiate  generics from this --
  25. -- unit, or you link  this unit with other files  to produce an executable, --
  26. -- this  unit  does not  by itself cause  the resulting  executable  to  be --
  27. -- covered  by the  GNU  General  Public  License.  This exception does not --
  28. -- however invalidate  any other reasons why  the executable file  might be --
  29. -- covered by the  GNU Public License.                                      --
  30. --                                                                          --
  31. -- GNAT was originally developed  by the GNAT team at  New York University. --
  32. -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
  33. --                                                                          --
  34. ------------------------------------------------------------------------------
  35.  
  36. with Ada.Text_IO.Modular_Aux;
  37.  
  38. with System.Unsigned_Types; use System.Unsigned_Types;
  39. with System.WCh_Con;        use System.WCh_Con;
  40. with System.WCh_WtS;        use System.WCh_WtS;
  41.  
  42. package body Ada.Text_IO.Wide_Text_IO.Modular_IO is
  43.  
  44.    subtype TFT is Ada.Text_IO.File_Type;
  45.    --  File type required for calls to routines in Aux
  46.  
  47.    package Aux renames Ada.Text_IO.Modular_Aux;
  48.    --  We can share the normal Text_IO circuits for the non-string cases
  49.    --  since numeric values involve no wide character values, and the first
  50.    --  character of a wide character value (ESC or an upper half character)
  51.    --  always looks non-numeric for the Get case). For the Wide_String cases
  52.    --  we can share the normal Text_IO circuits by converting to String.
  53.  
  54.    ---------
  55.    -- Get --
  56.    ---------
  57.  
  58.    procedure Get
  59.      (File  : in File_Type;
  60.       Item  : out Num;
  61.       Width : in Field := 0)
  62.    is
  63.    begin
  64.       if Num'Size > Unsigned'Size then
  65.          Aux.Get_LLU (TFT (File), Long_Long_Unsigned (Item), Width);
  66.       else
  67.          Aux.Get_Uns (TFT (File), Unsigned (Item), Width);
  68.       end if;
  69.  
  70.    exception
  71.       when Constraint_Error => raise Data_Error;
  72.    end Get;
  73.  
  74.    procedure Get
  75.      (Item  : out Num;
  76.       Width : in Field := 0)
  77.    is
  78.    begin
  79.       Get (Current_Input, Item, Width);
  80.    end Get;
  81.  
  82.    procedure Get
  83.      (From : in Wide_String;
  84.       Item : out Num;
  85.       Last : out Positive)
  86.    is
  87.       S : constant String := Wide_String_To_String (From, WCEM_Upper);
  88.       --  String on which we do the actual conversion. Note that the method
  89.       --  used for wide character encoding is irrelevant, since if there is
  90.       --  a character outside the Standard.Character range then the call to
  91.       --  Aux.Gets will raise Data_Error in any case.
  92.  
  93.    begin
  94.       if Num'Size > Unsigned'Size then
  95.          Aux.Gets_LLU (S, Long_Long_Unsigned (Item), Last);
  96.       else
  97.          Aux.Gets_Uns (S, Unsigned (Item), Last);
  98.       end if;
  99.  
  100.    exception
  101.       when Constraint_Error => raise Data_Error;
  102.    end Get;
  103.  
  104.    ---------
  105.    -- Put --
  106.    ---------
  107.  
  108.    procedure Put
  109.      (File  : in File_Type;
  110.       Item  : in Num;
  111.       Width : in Field := Default_Width;
  112.       Base  : in Number_Base := Default_Base)
  113.    is
  114.    begin
  115.       if Num'Size > Unsigned'Size then
  116.          Aux.Put_LLU (TFT (File), Long_Long_Unsigned (Item), Width, Base);
  117.       else
  118.          Aux.Put_Uns (TFT (File), Unsigned (Item), Width, Base);
  119.       end if;
  120.    end Put;
  121.  
  122.    procedure Put
  123.      (Item  : in Num;
  124.       Width : in Field := Default_Width;
  125.       Base  : in Number_Base := Default_Base)
  126.    is
  127.    begin
  128.       Put (Current_Output, Item, Width, Base);
  129.    end Put;
  130.  
  131.    procedure Put
  132.      (To   : out Wide_String;
  133.       Item : in Num;
  134.       Base : in Number_Base := Default_Base)
  135.    is
  136.       S : String (To'First .. To'Last);
  137.  
  138.    begin
  139.       if Num'Size > Unsigned'Size then
  140.          Aux.Puts_LLU (S, Long_Long_Unsigned (Item), Base);
  141.       else
  142.          Aux.Puts_Uns (S, Unsigned (Item), Base);
  143.       end if;
  144.  
  145.       for J in S'Range loop
  146.          To (J) := Wide_Character'Val (Character'Pos (S (J)));
  147.       end loop;
  148.    end Put;
  149.  
  150. end Ada.Text_IO.Wide_Text_IO.Modular_IO;
  151.